#include "opencv2/core.hpp"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;


int main()
{
    Mat img,gray,dst;
    vector<Mat> BGR;
    Size imgsize;
    int col,row;
    VideoCapture cap("test.avi");
    cap >> img;
    imgsize = img.size();
    col=img.cols;
    row=img.rows;

    while(cap.read(img))
    {
        namedWindow("Formal");
        namedWindow("Gray");
        namedWindow("Track");
        
        //转换成灰度图
        cvtColor(img, gray, COLOR_BGR2GRAY);
        // equalizeHist(gray, gray);
        int low(100),high(200);
        // createTrackbar("Low", "Track", &low, 500);
        // createTrackbar("High", "Track", &high, 500);
        Canny(gray, dst, low, high);
        vector<vector<Point>> contours;
        vector<Rect> boundRect(contours.size());
        findContours(dst, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
        Rect tan;
        for(size_t t=0; t<contours.size(); t++)
        {
            tan=boundingRect(contours[static_cast<int>(t)]);
            if(tan.area()>60)
                rectangle(img, boundingRect(contours[static_cast<int>(t)]), Scalar(0,0,255));
        }

        imshow("Formal", img);
        imshow("Gray", gray);
        imshow("Canny", dst);

        if(waitKey(13) == 27) break;
    }

    destroyAllWindows();
    return 0;
}